<template>
  <div class="supplier-slide-from">
    <el-form :model="form" :rules="rules" ref="form" :label-width="formLabelWidth">
      <el-form-item label="字段名称" prop="title">
        <el-col :span="12">
          <el-input v-model="form.title"></el-input>
        </el-col>
      </el-form-item>

      <el-form-item label="英文标识" prop="iden">
        <el-col :span="12">
          <el-input :disabled="row.id?true:false" v-model="form.iden"></el-input>
        </el-col>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submitForm('form')">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "supplier-slide-from",
  props: {
    row: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      form: {
        title: "",
        bid: "",
      },
      rules: {
        title: [{ required: true, message: "请输入表名称", trigger: "blur" }],
        iden: [{ required: true, message: "请输入英文标识", trigger: "blur" }]
      },
      formLabelWidth: "120px",
      bool: true
    };
  },
  created() {
    if (JSON.stringify(this.row) != "{}") {
      this.form = JSON.parse(JSON.stringify(this.row))
    }
  },
  mounted() {},
  methods: {
    addBd(params) {
      params.bid = this.$route.query.id;
      this.$api.getCharacter.characterCateSaveadd(params).then(res => {
        if (res.data.code == 200) {
          this.$emit("hideDio", true);
          this.$fnc.alertSuccess({ text: "添加成功" });
        } else {
          this.$fnc.alertError(res.data.code_desc, res.data.result);
        }
      });
    },
    editBd(params) {
      this.$api.getCharacter.characterCateSaveEdit(params).then(res => {
        if (res.data.code == 200) {
          this.$emit("hideDio", true);
          this.$fnc.alertSuccess({ text: "修改成功" });
        } else {
          this.$fnc.alertError(res.data.code_desc, res.data.result);
        }
      });
    },

    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.$bus.$emit("hide-from");
          var params = {};
          params = this.form;
          if (params.id) {
            this.editBd(params);
          } else {
            this.addBd(params);
          }
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
};
</script>
<style lang='less' scoped>
</style>
